

package com.googlecode.flac4j.format.metadata;


import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;


/**
 * Constants for <code>METADATA_BLOCK</code> type.
 *
 * @author Jin Kwon <jinahya at gmail.com>
 */
@XmlEnum(Integer.class)
public enum BlockType {


    /** STREAMINFO. */
    @XmlEnumValue("0")
    STREAMINFO(0),
    /** PADDING. */
    @XmlEnumValue("2")
    PADDING(1),
    /** APPLICATION. */
    @XmlEnumValue("2")
    APPLICATION(2),
    /** SEEKTABLE. */
    @XmlEnumValue("3")
    SEEKTABLE(3),
    /** VORBIS_COMMENT. */
    @XmlEnumValue("4")
    VORBIS_COMMENT(4),
    /** CUESHEET. */
    @XmlEnumValue("5")
    CUESHEET(5),
    /** PICTURE. */
    @XmlEnumValue("6")
    PICTURE(6);


    /**
     * Finds constant mapped to given <code>typeValue</code>.
     *
     * @param value block type value
     * @return mapped block type.
     */
    public static BlockType valueOf(final int value) {

        for (BlockType blockType : BlockType.values()) {
            if (blockType.getValue() == value) {
                return blockType;
            }
        }

        throw new IllegalArgumentException("unknown type: " + value);
    }


    /**
     * Creates a new instance.
     *
     * @param value block type value
     */
    BlockType(final int value) {
        this.value = value;
    }


    /**
     * Returns value.
     *
     * @return value
     */
    public int getValue() {
        return value;
    }


    /** value. */
    private final int value;


}

